Imports AUtility

Partial Public Class Ranking
    Inherits System.Web.UI.Page

    Dim selectStr As String = ""

    Public Function AddRedniBroj(ByVal dt As DataTable) As DataTable
        Dim i As Integer = 0
        dt.Columns.Add("RedniBroj")
        For Each row As DataRow In dt.Rows
            i = i + 1
            row("RedniBroj") = i
        Next
        Return dt
    End Function

    Private Sub Ranking_Ljeto_2009()
        Try
            selectStr = String.Format("SELECT ImePrezime, IgracId, 100*ROUND(Cast(SUM(BodLiga) as float)/COUNT(*), 2) AS Ranking FROM vRanking WHERE SezonaId > 8 AND SezonaId < 15 GROUP BY ImePrezime,IgracId ORDER BY Ranking DESC")
            If (gvRenking Is Nothing) Then
                gvRenking = New GridView
            End If
            gvRenking.DataSource = AddRedniBroj(DataAccess.GetDataTable(GlobalTenisLiga.ConnectionString, selectStr))
            gvRenking.DataBind()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

    Private Sub Ranking_Zima2009_2010()
        Try
            selectStr = String.Format("SELECT ImePrezime, IgracId, 100*ROUND(Cast(SUM(BodLiga) as float)/COUNT(*), 2) AS Ranking FROM vRanking WHERE SezonaId > 14 AND SezonaId <18 GROUP BY ImePrezime,IgracId ORDER BY Ranking DESC")
            If (gvRenking2 Is Nothing) Then
                gvRenking2 = New GridView
            End If
            gvRenking2.DataSource = AddRedniBroj(DataAccess.GetDataTable(GlobalTenisLiga.ConnectionString, selectStr))
            gvRenking2.DataBind()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

    Private Sub Ranking_Ljeto_2010()
        Try
            'selectStr = String.Format("SELECT ImePrezime, IgracId, 100*ROUND(Cast(SUM(BodLiga) as float)/COUNT(*), 2) AS Ranking FROM vRanking WHERE SezonaId > 17 GROUP BY ImePrezime,IgracId ORDER BY Ranking DESC")
            selectStr = String.Format("SELECT ImePrezime, IgracId, 100*ROUND(Cast(SUM(BodLiga) as float)/COUNT(*), 2) AS Ranking FROM vRanking WHERE SezonaId > 17 AND IgracId NOT IN ( SELECT IgracId FROM RankingExclude ) GROUP BY ImePrezime,IgracId ORDER BY Ranking DESC")

            If (gvRenking3 Is Nothing) Then
                gvRenking3 = New GridView
            End If
            gvRenking3.DataSource = AddRedniBroj(DataAccess.GetDataTable(GlobalTenisLiga.ConnectionString, selectStr))
            gvRenking3.DataBind()
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Ranking_Ljeto_2010()
        Ranking_Ljeto_2009()
        Ranking_Zima2009_2010()
    End Sub

End Class